package com.kuaimacode.kframework.api.service.sys;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kuaimacode.kframework.common.Constant;
import com.kuaimacode.kframework.mybatis.mapper.sys.AgentOrderRewardMapper;
import com.kuaimacode.kframework.mybatis.models.sys.AgentOrderReward;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @author 中元
 * @date 2019/04/02
 */
@Service
public class  AgentOrderRewardService extends ServiceImpl<AgentOrderRewardMapper, AgentOrderReward> {

	/**
	 *  分页查找所有的数据
	 * @param pageNum 当前页码，从1开始
	 * @param pageSize  一页显示多少行
	 * @return
	 */
	public PageInfo<AgentOrderReward> findAll(int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize,true,false,null);
		List<AgentOrderReward> datas = baseMapper.selectList(null);
		return new PageInfo<AgentOrderReward>(datas);
	}

	/**
	 * 根据分站id查询配置的数据
	 * @param agentId
	 * @return
	 */
	public List<AgentOrderReward> findAllByAgentId(String agentId) {
			QueryWrapper<AgentOrderReward> qryWrapper = new QueryWrapper<>();
			agentId = Optional.ofNullable(agentId).orElse( Constant.DEFAULT_AGENT_ID);
			qryWrapper.eq("agent_id", agentId);
			return baseMapper.selectList(qryWrapper);
		}
}

